
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - Bootstrap Table</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">

    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">

    <link href="../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">

    <link href="../css/plugins/chosen/chosen.css" rel="stylesheet">

    <link href="../css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">

    <link href="../css/plugins/cropper/cropper.min.css" rel="stylesheet">

    <link href="../css/plugins/switchery/switchery.css" rel="stylesheet">

    <link href="../css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">

    <link href="../css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">

    <link href="../css/plugins/datapicker/datepicker3.css" rel="stylesheet">

    <link href="../css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="../css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">

    <link href="../css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">

    <link href="../css/plugins/clockpicker/clockpicker.css" rel="stylesheet">

    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="alert alert-block hide" id="warning-block">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <h4 >提示</h4><span id="msg_txt"></span>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>应用</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a href="#">选项1</a>
                        </li>
                        <li><a href="#">选项2</a>
                        </li>
                    </ul>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <!-- Example Events -->
            <div class="example-wrap">
                <div class="example">
                    <div class="btn-group hidden-xs" id="CommandToolbar" role="group">
                        <button type="button" class="btn btn-outline btn-default btn-primary" data-toggle="modal" data-target="#add-modal">
                            <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                        </button>
                        <button type="button" class="btn btn-outline btn-default btn-primary" onclick="edit_modal()">
                            <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                        </button>
                        <button type="button" class="btn btn-outline btn-default btn-primary"  onclick="delete_modal()">
                            <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                        </button>
                    </div>
                    <table data-toggle="table" data-url="/command/table" id="bag_table" data-mobile-responsive="true" data-sort-name="Score" data-sort-order="desc"
                           data-search="true" data-pagination="true" data-maintain-selected="true" data-show-columns="true" data-toolbar="#CommandToolbar">
                        <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="id">ID</th>
                            <th data-field="title">模块名称</th>
                            <th data-field="lable">传输名称</th>
                            <th data-field="active">触发动作</th>
                            <th data-field="value">传输值</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Events -->
        </div>
    </div>
</div>
<form method="post" action="" class="form-horizontal" enctype="multipart/form-data" role="form" id="form_data" onsubmit="return check_form()" >
    <div class="modal inmodal" id="add-modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-laptop modal-icon"></i>
                    <h4 class="modal-title">添加</h4>
                    <small class="font-bold">这里可以显示副标题。
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <div class="row">
                            <div class="col-sm-12">
                                <label class="col-sm-3 control-label">应用名称</label>
                                <div class="col-sm-8">
                                    <input id="add_name" placeholder="新应用" class="form-control">
                                    <span class="help-block m-b-none">请输入新建应用的名字</span>
                                </div>
                            </div>
                            <div id="file-pretty" class="col-sm-12">
                                <div class="back-change">
                                    <label class="control-label col-sm-3">文件选择（单选）</label>
                                    <div class="col-sm-8">
                                        <input type="file" id="add_file" ><!-- class="form-control"> -->
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
<form method="post" action="" class="form-horizontal" role="form" id="form_data1" enctype="multipart/form-data" onsubmit="return edit_info()" >
    <div class="modal inmodal fade" id="edit-modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Close</span></button>
                    <h4 class="modal-title">编辑</h4>
                    <small class="font-bold">这里可以显示副标题。
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <label class="col-sm-3 control-label">应用名称</label>
                            <div class="col-sm-8">
                                <input id="edit_name" placeholder="新应用" class="form-control">
                                <span class="help-block m-b-none">请输入编辑应用的名字</span>
                            </div>
                        </div>
                        <div class="col-sm-12">
                            <label class="col-sm-3 control-label">原始图标</label>
                            <div class="col-sm-8">
                                <input id="edit_filename" placeholder="路径" class="form-control"  readonly>
                                <span class="help-block m-b-none">保存在服务器端文件的路径</span>
                            </div>
                        </div>
                        <div id="file-pretty" class="col-sm-12">
                            <div class="back-change">
                                <label class="control-label col-sm-3">文件选择（单选）</label>
                                <div class="col-sm-8">
                                    <input type="file" id="edit_file" ><!-- class="form-control"> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>
</form>
<form method="post" action="" class="form-horizontal" role="form" id="form_data2" onsubmit="return delete_info()" >
    <div class="modal inmodal fade" id="delete-modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <h2 id="delete_text" style="font-size:14px;">Close</h2>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">删除</button>
                </div>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">

    function msg_show(txt){
        bootbox.alert(txt);
    }

    //显示删除
    function delete_modal(){
        var rows = $("#bag_table").bootstrapTable('getSelections', function (row) {
            return row;
        });
        if(rows.length == 0)
        {
            msg_show('至少选择一项');
            return false;
        }
        var namelist = "是否要删除应用：";
        for (var i = 0; i < rows.length; i++) {
            namelist +=  "<" + rows[i].id + ">" + rows[i].name+"\n";
        }
        //msg_show(namelist);
        $("#delete_text").text(namelist);
        $('#delete-modal').modal('show');
    }

    //显示编辑
    function edit_modal(){
        var rows = $("#bag_table").bootstrapTable('getSelections', function (row) {
            return row;
        });
        if(rows.length == 1)
        {
            $('#edit_name').val(rows[0].name);
            $('#edit_filename').val(rows[0].ico);
            $('#edit-modal').modal('show');
            return true;

        }else if(rows.length == 2){
            if(rows[0].id == "ID"){
                msg_show("选中了两行");
                $('#edit_name').val(rows[1].name);
                $('#edit_filename').val('.'+rows[1].ico);
                $('#edit-modal').modal('show');
                return true;
            }
        }
        msg_show("只能选择一项进行编辑!");
        return false;
    }

    // 删除表单
    function delete_info(){
        var rows = $("#bag_table").bootstrapTable('getSelections', function (row) {
            return row;
        });
        if(rows.length == 0)
        {
            alert('Error！');
            return false;
        }
        var _list =[];
        for (var i = 0; i < rows.length; i++) {
            _list[i] = rows[i].id;
        }
        $.ajax({
            url: "/bag/delete",
            data:{"ids":_list},
            type: "post",
            success:function(data)
            {
                if(data =="ok")
                {
                    msg_show('操作成功');
                    location.reload();
                }
                else
                {
                    msg_show('操作失败');
                }
            },
            error:function()
            {
                msg_show('请求出错');
            }
        });

        return false;
    }

    // 编辑表单
    function edit_info(){
        var formdata = new FormData();
        var rows = $("#bag_table").bootstrapTable('getSelections', function (row) {
            return row;
        });
        if(rows.length != 1)
        {
            alert("编辑应用只能单选！！！");
            return false;
        }
        var file = $("#edit_file").attr("value");
        var urlStr = "/bag/edit";
        if(file ==null){
            urlStr = "/bag/editName";
        }else{
            formdata.append("file",file);
        }
        var oldfile = rows[0].ico;
        var name = $("#edit_name").val();
        var id = rows[0].id;
        formdata.append("name",name);
        formdata.append("id",id);
        formdata.append("oldfile",oldfile);
        msg_show("提交id" +id+ "--过去文件:" +oldfile+ "--文件名称:" + name);
        $.ajax({
            url: urlStr,
            data: formdata,
            type: "post",
            contentType: false,
            processData: false,
            success:function(data)
            {
                if(data == "ok")
                {
                    msg_show("提交成功");

                    location.reload();
                }
                else
                {
                    msg_show('操作失败');
                }
            },
            error:function()
            {
                msg_show('请求出错');
            }
        });

        return false;
    }

    // 提交表单
    function check_form(){
        var form = new FormData();
        var name = $("#add_name").val();
        var file = document.getElementById("add_file").files[0];
        form.append("name",name);
        form.append("file",file);
        //alert("获得文件");
        //formData.append("name",name);
        if(!name)
        {
            alert('用户名不能为空！');
            return false;
        }
        //var form_data = $('#form_data').serialize();

        // 异步提交数据到action/add_action.php页面
        $.ajax({
            url: "/bag/add",
            data: form,
            type: "post",
            contentType: false,
            processData: false,
            success:function(data)
            {
                if(data == "ok")
                {
                    msg_show("提交成功");

                    location.reload();
                }
                else
                {
                    msg_show('操作失败');
                }
            },
            error:function()
            {
                msg_show('请求出错');
            }
        });

        return false;
    }
</script>

<!-- 全局js -->
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>

<!-- bootbox Alert -->
<script src="../js/bootbox.min.js"></script>

<!-- 自定义js -->
<script src="../js/content.js?v=1.0.0"></script>
<script src="../js/plugins/prettyfile/bootstrap-prettyfile.js"></script>

<!-- Chosen -->
<script src="../js/plugins/chosen/chosen.jquery.js"></script>

<!-- JSKnob -->
<script src="../js/plugins/jsKnob/jquery.knob.js"></script>

<!-- Input Mask-->
<script src="../js/plugins/jasny/jasny-bootstrap.min.js"></script>

<!-- Data picker -->
<script src="../js/plugins/datapicker/bootstrap-datepicker.js"></script>

<!-- Prettyfile -->
<script src="../js/plugins/prettyfile/bootstrap-prettyfile.js"></script>

<!-- NouSlider -->
<script src="../js/plugins/nouslider/jquery.nouislider.min.js"></script>

<!-- Switchery -->
<script src="../js/plugins/switchery/switchery.js"></script>

<!-- IonRangeSlider -->
<script src="../js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>

<!-- iCheck -->
<script src="../js/plugins/iCheck/icheck.min.js"></script>

<!-- MENU -->
<script src="../js/plugins/metisMenu/jquery.metisMenu.js"></script>

<!-- Color picker -->
<script src="../js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>

<!-- Clock picker -->
<script src="../js/plugins/clockpicker/clockpicker.js"></script>

<!-- Image cropper -->
<script src="../js/plugins/cropper/cropper.min.js"></script>

<!-- <script src="../js/demo/form-advanced-demo.js"></script> -->

<!-- Bootstrap table -->
<script src="../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<!-- Peity -->
<script src="../js/demo/bootstrap-table-demo.js"></script>



</body>

</html>
